package com.shell.provider.message.service.impl;

import com.shell.customer.accreditation.vo.AuthenticatingCusVo;
import com.shell.customer.base.dao.CusInfoModifyDao;
import com.shell.customer.base.service.CusRecService;
import com.shell.customer.base.vo.CusAcctVo;
import com.shell.customer.base.vo.CusRecModVo;
import com.shell.customer.group.service.CusGrpService;
import com.shell.customer.po.CusGrp;
import com.shell.provider.message.service.MsgTipService;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("msgTipService")
public class MsgTipServiceImpl implements MsgTipService {
	@Autowired
	private CusInfoModifyDao cusInfoModifyDao;
	@Autowired
	private CusRecService cusRecService;
	@Autowired
	private CusGrpService cusGrpService;

	public int getMsgCountForCusTrial(String cusId) {
		String[] grpIdArr = null;
		List<CusGrp> grps = this.cusGrpService.selectCusGroupByTagCode(cusId, "GROUP_FIRST_TRIAL");
		if (grps != null) {
			List<String> grpArr = new ArrayList();
			for (CusGrp grp : grps) {
				grpArr.add(grp.getGrpId());
			}
			grpIdArr = (String[]) grpArr.toArray(new String[grpArr.size()]);
		}
		List<AuthenticatingCusVo> cuss = this.cusRecService.getAuthenticatingCus(null, grpIdArr, "2,4", null, null);
		return cuss == null ? 0 : cuss.size();
	}

	public int getMsgCountForCusFinal(String cusId) {
		String[] grpIdArr = null;
		List<CusGrp> grps = this.cusGrpService.selectCusGroupByTagCode(cusId, "GROUP_LAST_TRIAL");
		if (grps != null) {
			List<String> grpArr = new ArrayList();
			for (CusGrp grp : grps) {
				grpArr.add(grp.getGrpId());
			}
			grpIdArr = (String[]) grpArr.toArray(new String[grpArr.size()]);
		}
		List<AuthenticatingCusVo> cuss = this.cusRecService.getAuthenticatingCus(null, grpIdArr, "3", null, null);
		return cuss == null ? 0 : cuss.size();
	}

	public int getMsgCountForAcctTrial(String cusId) {
		CusAcctVo acctVo = new CusAcctVo();
		acctVo.setAcctState("R");
		String tagCode = "GROUP_FIRST_TRIAL";
		String[] grpIdArr = getGrpIds(tagCode, cusId);
		acctVo.setGrpIds(grpIdArr);
		return this.cusInfoModifyDao.getAprvAccts(acctVo).size();
	}

	private String[] getGrpIds(String tagCode, String cusId) {
		List<CusGrp> grps = this.cusGrpService.selectCusGroupByTagCode(cusId, tagCode);
		String[] grpIdArr = null;
		if (grps != null) {
			List<String> grpArr = new ArrayList();
			for (CusGrp grp : grps) {
				grpArr.add(grp.getGrpId());
			}
			grpIdArr = (String[]) grpArr.toArray(new String[grpArr.size()]);
		}
		return grpIdArr;
	}

	public int getMsgCountForAcctFinal(String cusId) {
		CusAcctVo acctVo = new CusAcctVo();
		acctVo.setAcctState("E");
		String tagCode = "GROUP_LAST_TRIAL";
		String[] grpIdArr = getGrpIds(tagCode, cusId);
		acctVo.setGrpIds(grpIdArr);
		return this.cusInfoModifyDao.getAprvAccts(acctVo).size();
	}

	public int getMsgCountForCusModifyTrial(String cusId) {
		CusRecModVo modVo = new CusRecModVo();
		modVo.setCusState("2");
		String tagCode = "GROUP_FIRST_TRIAL";
		String[] grpIdArr = getGrpIds(tagCode, cusId);
		modVo.setGrpIds(grpIdArr);
		return this.cusInfoModifyDao.getAprvCus(modVo).size();
	}

	public int getMsgCountForCusModifyFinal(String cusId) {
		CusRecModVo modVo = new CusRecModVo();
		modVo.setCusState("3");
		String tagCode = "GROUP_LAST_TRIAL";
		String[] grpIdArr = getGrpIds(tagCode, cusId);
		modVo.setGrpIds(grpIdArr);
		return this.cusInfoModifyDao.getAprvCus(modVo).size();
	}
}
